package com.ehualu.javahadoop.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ehualu.javahadoop.service.SumService;
import com.ehualu.javahadoop.until.Timeuntil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 吴敬超
 * @Date: 2020/3/2 11:28
 */


@Controller
@RequestMapping(value = "/restnum")
public class Controllers {

    @Autowired
    private SumService sumService;


    @RequestMapping(value = "/getnum", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, String> getnum(@RequestBody String json) {

        JSONObject jsonObject = JSON.parseObject(json);


        String startime = jsonObject.getString("startime");

        System.out.println(startime);


        String endtime = jsonObject.getString("endtime");

        System.out.println(endtime);

        String kkbhs = jsonObject.getString("kkbhs");

        System.out.println(kkbhs);


        Map<String, String> numinfos = new HashMap<String, String>();


        Timeuntil timeuntil = new Timeuntil();


        try {
            boolean timeflag = timeuntil.timeflag(endtime);

            if (timeflag) {


                numinfos = sumService.getkknum(startime, endtime, kkbhs);


            } else {


                System.out.println("查询的日期要小于当前日期");
                numinfos.put("0000000000000", "0");
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }


        return numinfos;
//

    }


}
